package ticketing_system.register_login;

import ticketing_system.Database.Database_vip;
import ticketing_system.Database.Database_vipDAO;
import ticketing_system.Factory.Price_Factory;
import ticketing_system.Factory.User;

import java.util.Scanner;

public class login {
    public static Object check() throws Exception {
        Scanner sc = new Scanner(System.in);
        Database_vipDAO dao = new Database_vipDAO();
        Database_vip a = new Database_vip();
        System.out.print("请输入您的用户名:");
        a.setUsername(sc.next());
        System.out.print("请输入您的密码:");
        a.setPassword(sc.next());
        Object res = dao.queryById(a);
        if (res != null) {
            System.out.println("尊贵的VIP会员，您已登陆成功！");
        } else {
            System.out.println("请重新核对您的账号和密码!");
            for (int i = 3; i > 0; i--) {
                System.out.println("您还有次" + i + "机会");
                System.out.print("请输入您的用户名:");
                a.setUsername(sc.next());
                System.out.print("请输入您的密码:");
                a.setPassword(sc.next());
                Object res1 = dao.queryById(a);
                if (res1 != null) {
                    System.out.println("尊贵的VIP会员，您已登陆成功！");
                    System.out.println("vip专属售票通道");
                    Price_Factory pf = new Price_Factory();
                    User u = pf.get_select(3);
                    u.price();
                    System.out.println("您的vip票正在打印中，请稍后...");
                    break;
                }else if(i==0) {
                    return (res == null);
                }
            }
            return res;
        }
        return res;
    }
}

